import Login from "@/pages/login/index";
import Home from "@/pages/home/index";
import App from "@/App";
import User from "@/pages/user";
import { createHashRouter, Navigate } from "react-router-dom";
import {
  ContainerOutlined,
  FileOutlined,
  FundViewOutlined,
  PieChartOutlined,
  SettingOutlined,
  UserOutlined,
} from "@ant-design/icons";
import { lazy, Suspense } from "react";

const Bank = lazy(() => import("@/pages/bank/index"));
const BankQuestion = lazy(() => import("@/pages/bank/question/index"));
const BankTags = lazy(() => import("@/pages/bank/tag/index"));
const QuesType = lazy(() => import("@/pages/bank/quesType/index"));
const Exam = lazy(() => import("@/pages/exam/index"));
const ExamPaperList = lazy(() => import("@/pages/exam/examPaperList/index"));
const AddExamPaper = lazy(() => import("@/pages/exam/addExamPaper/index"));
const Meeting = lazy(() => import("@/pages/meeting/index"));
const MeetingList = lazy(() => import("@/pages/meeting/meetingList/index"));
const MeetingConf = lazy(() => import("@/pages/meeting/meetingConf/index"));
export const managementMenu = [
  {
    id: "dashboard",
    path: "dashboard",
    element: <div>菜单</div>,
    handle: {
      name: "数据板",
      icon: <PieChartOutlined />,
    },
  },
  {
    id: "bank",
    path: "bank",
    element: (
      <Suspense fallback={<div>加载中...</div>}>
        <Bank />
      </Suspense>
    ),
    handle: {
      name: "题库",
      icon: <FileOutlined />,
    },
    children: [
      {
        id: "question",
        path: "question",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <BankQuestion />
          </Suspense>
        ),
        handle: {
          name: "题目管理",
          icon: <FileOutlined />,
        },
      },
      {
        id: "type",
        path: "type",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <QuesType />
          </Suspense>
        ),
        handle: {
          name: "题型管理",
          icon: <FileOutlined />,
        },
      },
      {
        id: "tag",
        path: "tag",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <BankTags />
          </Suspense>
        ),
        handle: {
          name: "标签管理",
          icon: <FileOutlined />,
        },
      },
    ],
  },
  {
    id: "exam",
    path: "exam",
    element: (
      <Suspense fallback={<div>加载中...</div>}>
        <Exam />
      </Suspense>
    ),
    handle: {
      name: "试卷库",
      icon: <ContainerOutlined />,
    },
    children: [
      {
        id: "examPaperList",
        path: "list",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <ExamPaperList />
          </Suspense>
        ),
        handle: {
          name: "试卷列表",
          icon: <FileOutlined />,
        },
      },
      {
        id: "examPaperAdd",
        path: "add",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <AddExamPaper />
          </Suspense>
        ),
        handle: {
          name: "添加试卷",
          icon: <FileOutlined />,
        },
      },
      {
        id: "examPaperShow",
        path: "show/:id",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <AddExamPaper />
          </Suspense>
        ),
        handle: {
          name: "编辑试卷",
          icon: <FileOutlined />,
          noShow:true,
        },
      },
    ],
  },
  {
    id: "meeting",
    path: "meeting",
    element: (
      <Suspense fallback={<div>加载中...</div>}>
        <Meeting />
      </Suspense>
    ),
    handle: {
      name: "面试管理",
      icon: <ContainerOutlined />,
    },
    children: [
      {
        id: "meetingList",
        path: "list",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <MeetingList />
          </Suspense>
        ),
        handle: {
          name: "面试列表",
          icon: <FileOutlined />,
        },
      },
      {
        id: "meetingConf",
        path: "conf/:id",
        element: (
          <Suspense fallback={<div>加载中...</div>}>
            <MeetingConf />
          </Suspense>
        ),
        handle: {
          name: "配置面试",
          icon: <FileOutlined />,
          noShow: true,
        },
      },
    ],
  },
  {
    id: "test",
    path: "test",
    element: <div>菜单</div>,
    handle: {
      name: "考试库",
      icon: <FundViewOutlined />,
    },
  },
  {
    id: "user",
    path: "user",
    element: <User></User>,
    handle: {
      name: "用户库",
      icon: <UserOutlined />,
    },
  },
  {
    id: "setting",
    path: "setting",
    element: <div>菜单</div>,
    handle: {
      name: "设置",
      icon: <SettingOutlined />,
    },
  },
];

const router = createHashRouter([
  {
    path: "/",
    element: <App></App>,
    children: [
      {
        path: "home",
        element: <Home></Home>,
        handle: {
          name: "主页",
        },
        children: [
          {
            index: true,
            element: <Navigate to={managementMenu[0].path} replace />,
          },
          ...managementMenu,
        ],
      },
      {
        path: "login",
        element: <Login></Login>,
        handle: {
          name: "登录",
        },
      },
    ],
  },
]);

export default router;
